package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	jsoniter "github.com/json-iterator/go"
	"github.com/json-iterator/go/extra"
	"go.mongodb.org/mongo-driver/bson"
	"my-gameserver-go/logic/db"
	persis "my-gameserver-go/logic/persistenceObj"
	"my-gameserver-go/logic/server"
	"unicode"
)

func main() {
	//test2()
	start()
	//dbTest()
}
func start() {
	gameServer := server.NewGameServer()
	//启动server
	gameServer.Start()

}

func test2() {
	slice := make([]byte, 12)
	dataBuff := bytes.NewBuffer(slice)
	//创建一个存放bytes字节的缓冲
	//dataBuff := bytes.NewBuffer([]byte{})
	//写dataLen
	if err := binary.Write(dataBuff, binary.LittleEndian, int32(1)); err != nil {
	}
	fmt.Println()
}

func test() {
	extra.SetNamingStrategy(LowerCaseWithCamer)
	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	u := persis.User{UserName: "SbASSs"}
	v, _ := json.Marshal(u)

	k := &persis.User{}
	json.Unmarshal(v, k)

	fmt.Println(k)
}
func LowerCaseWithCamer(name string) string {
	newName := []rune{}
	for i, c := range name {
		if i == 0 {
			newName = append(newName, unicode.ToLower(c))
		} else {
			newName = append(newName, c)
		}
	}
	return string(newName)
}

func dbTest() {
	uri := "mongodb://slguser:slguser@192.168.2.66:27099/slguser"
	mongoconn := db.NewMongoDbConn(uri, "slguser")
	//fmt.Println(reflect.TypeOf(mongoconn).Kind().String())
	//var player = &Player.Player{}
	//mongoconn.FindOne(bson.M{"playerId": uint64(21323121)}, player)
	//player.ServerId = 6666
	user := &persis.User{}
	//mongoconn.Save(user)
	mongoconn.FindOne(bson.M{"username": "gouser"}, user)
	//var player = &Player.Player{
	//	PlayerId:   21323121,
	//	PlayerName: "test0",
	//	ServerId:   222,
	//}
	//mongoconn.Save(player)
	select {}
}
